#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;

template <typename Container>
void display(const Container &con)
{
    for(auto &elem : con)
    {
        cout << elem << "  ";
    }
    cout << endl;
}

void test()
{
    cout << "sizeof(list<int>) = " << sizeof(list<int>) << endl;
    cout << "sizeof(list<long>) = " << sizeof(list<long>) << endl;
    list<int> number = {1, 3, 5, 7, 9, 8, 6, 4, 2};
    display(number);

    cout << endl << "在list的尾部进行插入与删除" << endl;
    number.push_back(10);
    number.push_back(20);
    display(number);
    number.pop_back();
    display(number);

    //获取list中的第一个元素的首地址？
    &number;//error，不能得到list的第一个元素的首地址
    &*number.begin();//ok,可以取第一个元素首地址

    cout << endl << "在list的任意位置进行插入" << endl;
    list<int>::iterator it = number.begin();
    ++it;
    ++it;
    cout << "*it = " << *it << endl;
    number.insert(it, 100);
    display(number);
    cout << "*it = " << *it << endl;

    cout << endl;
    cout << "*it = " << *it << endl;
    number.insert(it, 8, 666);
    display(number);
    cout << "*it = " << *it << endl;

    cout << endl;
    list<int> lst = {11, 44, 55};
    cout << "*it = " << *it << endl;
    number.insert(it, lst.begin(), lst.end());
    display(number);
    cout << "*it = " << *it << endl;

    cout << endl;
    cout << "*it = " << *it << endl;
    number.insert(it, {777, 999, 888});
    display(number);
    cout << "*it = " << *it << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}


